package org.prs.persistence;

import com.prs.util.PrsException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.prs.model.Organisation;
import org.prs.persistence.connector.MySQLDatabaseConnector;

public class OrganisationDatabasePersistence {

    private Connection conn;
    private ResultSet result;

    public Organisation getOrganisation() {
        Organisation organisation = new Organisation();
        conn = MySQLDatabaseConnector.getConnection();
        PreparedStatement selectOrganisation = null;
        try {
            selectOrganisation = conn.prepareStatement("select * from organisationinfo where id=1");
            result = selectOrganisation.executeQuery();
            while (result.next()) {
                organisation = getOrganisation(result);
            }
        } catch (SQLException e) {
           throw  new PrsException(e);
           
        }
        return organisation;

    }

    private Organisation getOrganisation(ResultSet result) {
        Organisation organisation = new Organisation();
        try {
            organisation.setId(result.getInt("id"));
            organisation.setLocation(result.getString("location"));
            organisation.setName(result.getString("name"));
            organisation.setWebsite(result.getString("website"));
        } catch (SQLException e) {
            throw  new PrsException(e);
        }
        return organisation;

    }
}
